<!--# layout("/common/layout.html",{"jsBase":"/js/promote/promoteCommission/"}){ -->

<form class="layui-form layui-form-pane" id="addForm"  lay-filter="editform">
    <input type="hidden" name="tenantId" id="tenantId">

    <div class="layui-row" id="orderTypeDiv">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">产品类型</label>
                <div class="layui-input-inline">
                    <layui:simpleDataSelect name="orderType"  data="${orderTypes}" value=""
                                            attrId="orderType" attrName="orderName" laySearch="true" layFilter="orderTypeFilter" id="orderType" />
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">佣金比例</label>
				<div class="layui-input-inline">
                                <input type="text" placeholder="百分比，比如20表示20%" name="commissionRatio" id="commissionRatio" autocomplete="off" maxlength="50" class="layui-input" lay-verify="required|number">
				</div>
            </div>
        </div>
    </div>
    <layui:submitButtons id="addButton" />
</form>
<!--#} -->
<script>
layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
}).define([ 'form', 'laydate', 'table','loading','promoteCommissionApi'], function(exports) {
    var form = layui.form;
    var promoteCommissionApi = layui.promoteCommissionApi;
    var index = layui.index;
    var isNew = true;
    var checkFlag = true;
    <!--# if(!(isEmpty(promoteCommissionJson))){  -->
    isNew = false;
    <!--# } -->
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
            form.on('select(orderTypeFilter)', function(data){
                $.ajax({
                    type: 'POST',
                    url: "${ctxPath}/promote/promoteCommission/check.json",
                    data: {
                        orderType:data.value
                    },
                    dataType:'json',
                    success: function(data){
                        if(data.code!=0){
                            Common.info("产品类型重复");
                            checkFlag = false;
                        }else{
                            checkFlag = true;
                        }
                    }
                });

            });
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();
                if($("#orderType").val()==null||$("#orderType").val()==""){
                    Common.info("请选择产品类型");
                    return;
                }
                if(!checkFlag){
                    Common.info("产品类型重复");
                    return;
                }
                form.on('submit(form)', function(){
                    promoteCommissionApi.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();
    <!--# if(!(isEmpty(promoteCommissionJson))){  -->
    var formJson = ${promoteCommissionJson};
    form.val("editform",formJson);
    $('#orderTypeDiv').hide();
    <!--# } -->
});
</script>
